package Chat;

import windows.GameConsole;


public class CollisionCheck {
	
	//$@danny:team:imagenaam|hunter:20.0;25.0
	
		public static String[] split(String i)
		{
			String s[] = i.split("\\|");		
			
			String[] a = s[1].split(":");
			
			String[] b = a[1].split(";");		
			
			return b;
		} 
		
		public static String splitNaam(String i)
		{
			String s[] = i.split("\\|");		
			
			String[] a = s[0].split(":");
			
			System.out.println(a[0]);
			
			return a[0];
		}
		
		public static void Collision2(String var1, String var2)
		{

			 String TEMP2 = var2;
			 String TEMP1 = var1;
			 String TEMP3 = null;
			 String TEMP4 = null;
			 String input1 = null;
			 String input2 = null;
			 int i = 0;
			
			 while(true){

				 
				 if(TEMP3 == null)
				 {
					 TEMP3 = splitNaam(TEMP1);
				 }
				 else
				 {
					 TEMP4 = splitNaam(TEMP2);
				 }
				 
				 System.out.println("t5-"+TEMP3);
				 System.out.println("t4-"+TEMP4);
				 
				 if(!(TEMP3.equals(TEMP4)) )
				 {				 	
					 	if (input1 == null)
					 	{
					 		input1 = TEMP1;
					 		i = 1; 
					 	}
					 	else
					 	{
					 		input2 = TEMP2;
					 		i = 2;
					 	}				 	
					 	if(i == 2)
					 	{
					 		if(collision(input1, input2))
					 		{
					 			System.out.println("Collision Detected");
					 			input1 = null;
					 			input2 = null;
					 			TEMP3 = null;
								TEMP4 = null;
								A_Chat_Server_Return.TEMP0 = null;
								A_Chat_Server_Return.TEMP1 = null;
					 			i = 0;
					 			break;
					 		}
					 		else
					 		{
					 			System.out.println("No Collision");
					 			input1 = null;
					 			input2 = null;
					 			TEMP3 = null;
								TEMP4 = null;
								A_Chat_Server_Return.TEMP0 = null;
								A_Chat_Server_Return.TEMP1 = null;
					 			i = 0;
					 			break;
					 		}
					 	}	 
				 }
				 else
				 {
					 System.out.println("Naam Gelijk");
					 TEMP3 = null;
					 TEMP4 = null;
					 A_Chat_Server_Return.TEMP1 = null;					 
					 break;
				 }
			 }		
		}
		
		public static boolean collision(String coordinaat1, String coordinaat2)
		{
			
			double ax = Double.parseDouble(split(coordinaat1)[0]);
			double ay = Double.parseDouble(split(coordinaat1)[1]);
			
			double bx = Double.parseDouble(split(coordinaat2)[0]);
			double by = Double.parseDouble(split(coordinaat2)[1]);
			int r = 50;
			
			boolean ycollision = false;
			boolean xcollision = false;
			boolean totalcollision = false;
			
			if(ay > by) 				// a vaart boven b
			{
				if ((ay-r) <= (by+r)) 	// binnen y-bereik
				{
					ycollision = true;
				}
				else					// buiten y-bereik
				{
					ycollision= false;
				}
			}
			else						// a vaart beneden b
			{
				if ((ay+r) >= (by-r)) 	// binnen y-bereik
				{
					ycollision = true;
				}
				else					// buiten y-bereik
				{		
					ycollision = false;
				}
			}
			
			if(ax < bx)					// a vaart links van b
			{
				if((ax+r) >= (bx-r))
				{
					xcollision = true;	// binnen x-bereik
					
				}
				else
				{
					xcollision = false;	// buiten x-bereik
				}
			}
			else						// a vaart rechts van b
			{
				if((ax-r) <= (bx+r))
				{
					xcollision = true;	// binnen x-bereik
					
				}
				else
				{
					xcollision = false;	// buiten x-bereik
				}
			}		
			
			
		if((xcollision && ycollision) == true )
		{
			totalcollision = true;
		}
		else
		{
			totalcollision = false;
		}
		return totalcollision;		
		
	}
		
	
}
	

